#include "StateManager.h"
#include "IntroState.h"
#include "MenuState.h"
#include "PlayState.h"

StateManager::StateManager(){
}

StateManager::~StateManager(){
}

void StateManager::initialize(StateType startState){
	currentState = getState(startState);
	currentState->initialize();
}

void StateManager::cleanup(){
	currentState->cleanup();
	delete currentState;
}

void StateManager::runCurrentState(){
	StateType newState = currentState->run();
	if(newState != NULL_STATE){
		changeState(newState);
	}
}

void StateManager::changeState(StateType type){
	currentState->cleanup();
	delete currentState;
	currentState = getState(type);
	currentState->initialize();
}

GameState* const StateManager::getState(StateType type){
	GameState* gameState;
	switch(type){
	case STATE_INTRO:
		gameState = new IntroState();
		break;
	case STATE_MENU:
		gameState = new MenuState();
		break;
	case STATE_PLAY:
		gameState = new PlayState();
		break;
	}
	return gameState;
}